package com.huifan.demo.revenue.servyou;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.huifan.demo.revenue.servyou.ServyouService.CODE_0000;

/**
 * @author: liuchenhui
 * @create: 2019-08-15 12:05
 **/
@SuppressWarnings("all")
public class TaxationCalculate {
    /**
     * 获取算税数据
     *
     * @param id 人员报送反馈id
     */
    public static Map<String, Object> getSkjsData(String id) {
        String request = ServyouService.ryxxfkztcx(id);

        JSONObject jsonObject = JSON.parseObject(request);
        String code = jsonObject.getString("code");
        String msg = jsonObject.getString("msg");
        JSONObject dataJson = jsonObject.getJSONObject("data");
        JSONArray bsjg = dataJson.getJSONArray("bsjg");
        if (!CODE_0000.equals(code)) {
            throw new RuntimeException(msg);
        }
        Map<String, Object> skjsData = new HashMap<>();

        Map<String, Object> ykyj = new HashMap<>();
        Map<String, List<Map<String, Object>>> flsd = new HashMap<>();
        Map<String, List<Map<String, Object>>> fjmsd = new HashMap<>();

        List<Map<String, Object>> zcgzxjlbList = new ArrayList<>();
        List<Map<String, Object>> jmsxfblbList = new ArrayList<>();

        for (int i = 0; i < bsjg.size(); i++) {
            JSONObject object = bsjg.getJSONObject(i);
            String xm = object.getString("xm");
            String zzlx = object.getString("zzlx");
            String zzhm = object.getString("zzhm");
            // FIXME: 2019-08-15 组装税款计算
            Map<String, Object> zcgzxjlb = new HashMap<>();
            zcgzxjlb.put("xm", xm);
            zcgzxjlb.put("zzlx", zzlx);
            zcgzxjlb.put("zzhm", zzhm);
            zcgzxjlb.put("sre", "10000");
            zcgzxjlb.put("jbylaobxf", "500");// 基本养老保险
            zcgzxjlb.put("jbylbxf", "200");// 基本医疗保险
            zcgzxjlb.put("zfgjj", "200"); // 住房公积金
//            zcgzxjlb.put("jmse", "10");// 减免税额
            zcgzxjlbList.add(zcgzxjlb);

            if (zcgzxjlb.get("jmse") != null) {
                Map<String, Object> jmsxfblb = new HashMap<>();
                jmsxfblb.put("xm", xm);
                jmsxfblb.put("zzlx", zzlx);
                jmsxfblb.put("zzhm", zzhm);
                jmsxfblb.put("jmfs", 0);
                jmsxfblb.put("sdxm", "0101");
                jmsxfblb.put("jmsx", "残疾、孤老、烈属减征个人所得税");
                jmsxfblb.put("jmxz", "《中华人民共和国个人所得税法》 中华人民共和国主席令第48号第五条第一项");
                jmsxfblb.put("jmje", 10);
                jmsxfblbList.add(jmsxfblb);
            }

        }
        ykyj.put("zcgzxjlb", zcgzxjlbList);
        ykyj.put("qkdysj", "是");
//        ykyj.put("jmsxfblb", jmsxfblbList);
        skjsData.put("ykyj", ykyj);
        return skjsData;
    }
}
